﻿Imports Hinshelwood.TFSStickyBuddy.Modules.Interfaces
Imports System.Net
Imports System.ComponentModel
Imports Microsoft.Practices.Composite.Events
Imports Hinshelwood.TFSStickyBuddy.Modules.Events

Namespace PresentationModels


    Public Class CredentialProviderPresentationModel
        Implements ICredentialProviderPresentationModel
        Implements INotifyPropertyChanged

        Private m_SelectedCredentials As NetworkCredential
        Private m_eventAggregator As IEventAggregator

        Public Property SelectedCredentials() As NetworkCredential Implements ICredentialProviderPresentationModel.SelectedCredentials
            Get
                Return m_SelectedCredentials
            End Get
            Set(ByVal value As NetworkCredential)
                If Not value Is m_SelectedCredentials Then
                    m_SelectedCredentials = value
                    OnPropertyChanged("SelectedCredentials")
                    m_eventAggregator.GetEvent(Of CredentialProvidedEvent).Publish(value)
                End If
            End Set
        End Property

        Public Sub New(ByVal eventAggregator As IEventAggregator)
            m_eventAggregator = eventAggregator
        End Sub

#Region " INotifyPropertyChanged "

        Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

        Public Sub OnPropertyChanged(ByVal PropertyName As String)
            If Not Application.Current.Dispatcher.CheckAccess Then
                Application.Current.Dispatcher.Invoke(New Action(Of String)(AddressOf OnPropertyChanged), PropertyName)
            End If
            If Not PropertyChangedEvent Is Nothing Then
                RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(PropertyName))
            End If
        End Sub

#End Region


    End Class

End Namespace